package com.lagou.mr;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class IntegerSortMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable> {
    IntWritable iValue = new IntWritable();//避免在map中声明变量会每次都重新声明浪费空间
    @Override
    //intwritable 自身实现了WritableComparable接口.所以直接具备了排序功能
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        iValue.set(Integer.valueOf(value.toString()));
        context.write(iValue, NullWritable.get());
    }
}
